﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex03.GarageLogic
{
    /// <summary>
    /// whell class which every vehicle own an array of wheels, have r_MaxAirPressureByManufacturer, m_ManufacturerName and m_CurrentAirPressure members
    /// </summary>
    internal class Wheel
    {
        private readonly float r_MaxAirPressureByManufacturer = 0;
        private string m_ManufacturerName = string.Empty;
        private float m_CurrentAirPressure = 0;        

        public Wheel(string i_ManufacturerName, float i_MaxAirPressureByManufacturer)        
        {
            m_ManufacturerName = i_ManufacturerName;       
            r_MaxAirPressureByManufacturer = i_MaxAirPressureByManufacturer;
        }
        
        /// <summary>
        /// pump the wheel by i_AirForWhell + m_CurrentAirPressure
        /// throw ValueOutOfRangeException when the i_AirForWhell smaller then  0 or i_AirForWhell + m_CurrentAirPressure bigger then r_MaxAirPressureByManufacturer
        /// </summary>
        /// <param name="i_AirForWhell">how much air pressure to fill</param>
        public void PumpWhell(float i_AirForWhell)
        {
            // Todo, check exception messages
            float k_MinAirPeessure = 0;

            if (i_AirForWhell < k_MinAirPeessure)
            {
                string exceptionMassage = "Minimum Air unit is " + k_MinAirPeessure;
                throw new ValueOutOfRangeException(k_MinAirPeessure, r_MaxAirPressureByManufacturer, exceptionMassage);
            }

            if (m_CurrentAirPressure + i_AirForWhell > r_MaxAirPressureByManufacturer)
            {
                string exceptionMassage = "Air amount overflows the maximum determined by manufacturer";
                throw new ValueOutOfRangeException(k_MinAirPeessure, r_MaxAirPressureByManufacturer, exceptionMassage);
            }
            else 
            {
                m_CurrentAirPressure += i_AirForWhell;
            }
        }

        public Wheel Clone()
        {
            return this.MemberwiseClone() as Wheel;
        }
        
        public float CurrentAirPressure
        {
            get { return m_CurrentAirPressure; }
            set { m_CurrentAirPressure = value; }
        }
       
        public float MaxAirPressureByManufacturer
        {
            get { return r_MaxAirPressureByManufacturer; }            
        }

        /// <summary>
        ///  Overriding <see cref="Object.ToString"/>
        /// </summary>
        /// <returns>string with thw whell members values</returns>
        public override string ToString()
        {
            return string.Format(
@"Wheel ManuFacturer: {0}
Current air pressure: {1}
Max air pressure: {2}"
                , m_ManufacturerName
                , m_CurrentAirPressure
                , r_MaxAirPressureByManufacturer);
        }
    }
}
